package com.baobao.dao;

import com.baobao.domain.Parent;

import java.util.Arrays;
import java.util.HashSet;
import java.util.LinkedHashSet;
import java.util.Set;

import javax.persistence.EntityManager;
import javax.persistence.NoResultException;
import javax.persistence.PersistenceContext;
import javax.persistence.Query;

import org.skyway.spring.util.dao.AbstractJpaDao;

import org.springframework.dao.DataAccessException;

import org.springframework.stereotype.Repository;

import org.springframework.transaction.annotation.Transactional;

/**
 * DAO to manage Parent entities.
 * 
 */
@Repository("ParentDAO")
@Transactional
public class ParentDAOImpl extends AbstractJpaDao<Parent> implements ParentDAO {

	/**
	 * Set of entity classes managed by this DAO.  Typically a DAO manages a single entity.
	 *
	 */
	private final static Set<Class<?>> dataTypes = new HashSet<Class<?>>(Arrays.asList(new Class<?>[] { Parent.class }));

	/**
	 * EntityManager injected by Spring for persistence unit BaoBao
	 *
	 */
	@PersistenceContext(unitName = "BaoBao")
	private EntityManager entityManager;

	/**
	 * Instantiates a new ParentDAOImpl
	 *
	 */
	public ParentDAOImpl() {
		super();
	}

	/**
	 * Get the entity manager that manages persistence unit 
	 *
	 */
	public EntityManager getEntityManager() {
		return entityManager;
	}

	/**
	 * Returns the set of entity classes managed by this DAO.
	 *
	 */
	public Set<Class<?>> getTypes() {
		return dataTypes;
	}

	/**
	 * JPQL Query - findParentByBbId2
	 *
	 */
	@Transactional
	public Set<Parent> findParentByBbId2(String bbId2) throws DataAccessException {

		return findParentByBbId2(bbId2, -1, -1);
	}

	/**
	 * JPQL Query - findParentByBbId2
	 *
	 */

	@SuppressWarnings("unchecked")
	@Transactional
	public Set<Parent> findParentByBbId2(String bbId2, int startResult, int maxRows) throws DataAccessException {
		Query query = createNamedQuery("findParentByBbId2", startResult, maxRows, bbId2);
		return new LinkedHashSet<Parent>(query.getResultList());
	}

	/**
	 * JPQL Query - findParentByPassword
	 *
	 */
	@Transactional
	public Set<Parent> findParentByPassword(String password) throws DataAccessException {

		return findParentByPassword(password, -1, -1);
	}

	/**
	 * JPQL Query - findParentByPassword
	 *
	 */

	@SuppressWarnings("unchecked")
	@Transactional
	public Set<Parent> findParentByPassword(String password, int startResult, int maxRows) throws DataAccessException {
		Query query = createNamedQuery("findParentByPassword", startResult, maxRows, password);
		return new LinkedHashSet<Parent>(query.getResultList());
	}

	/**
	 * JPQL Query - findParentByPasswordContaining
	 *
	 */
	@Transactional
	public Set<Parent> findParentByPasswordContaining(String password) throws DataAccessException {

		return findParentByPasswordContaining(password, -1, -1);
	}

	/**
	 * JPQL Query - findParentByPasswordContaining
	 *
	 */

	@SuppressWarnings("unchecked")
	@Transactional
	public Set<Parent> findParentByPasswordContaining(String password, int startResult, int maxRows) throws DataAccessException {
		Query query = createNamedQuery("findParentByPasswordContaining", startResult, maxRows, password);
		return new LinkedHashSet<Parent>(query.getResultList());
	}

	/**
	 * JPQL Query - findParentByBbId5Containing
	 *
	 */
	@Transactional
	public Set<Parent> findParentByBbId5Containing(String bbId5) throws DataAccessException {

		return findParentByBbId5Containing(bbId5, -1, -1);
	}

	/**
	 * JPQL Query - findParentByBbId5Containing
	 *
	 */

	@SuppressWarnings("unchecked")
	@Transactional
	public Set<Parent> findParentByBbId5Containing(String bbId5, int startResult, int maxRows) throws DataAccessException {
		Query query = createNamedQuery("findParentByBbId5Containing", startResult, maxRows, bbId5);
		return new LinkedHashSet<Parent>(query.getResultList());
	}

	/**
	 * JPQL Query - findParentByBbId4
	 *
	 */
	@Transactional
	public Set<Parent> findParentByBbId4(String bbId4) throws DataAccessException {

		return findParentByBbId4(bbId4, -1, -1);
	}

	/**
	 * JPQL Query - findParentByBbId4
	 *
	 */

	@SuppressWarnings("unchecked")
	@Transactional
	public Set<Parent> findParentByBbId4(String bbId4, int startResult, int maxRows) throws DataAccessException {
		Query query = createNamedQuery("findParentByBbId4", startResult, maxRows, bbId4);
		return new LinkedHashSet<Parent>(query.getResultList());
	}

	/**
	 * JPQL Query - findParentByPhoneContaining
	 *
	 */
	@Transactional
	public Set<Parent> findParentByPhoneContaining(String phone) throws DataAccessException {

		return findParentByPhoneContaining(phone, -1, -1);
	}

	/**
	 * JPQL Query - findParentByPhoneContaining
	 *
	 */

	@SuppressWarnings("unchecked")
	@Transactional
	public Set<Parent> findParentByPhoneContaining(String phone, int startResult, int maxRows) throws DataAccessException {
		Query query = createNamedQuery("findParentByPhoneContaining", startResult, maxRows, phone);
		return new LinkedHashSet<Parent>(query.getResultList());
	}

	/**
	 * JPQL Query - findParentByBbId1
	 *
	 */
	@Transactional
	public Set<Parent> findParentByBbId1(String bbId1) throws DataAccessException {

		return findParentByBbId1(bbId1, -1, -1);
	}

	/**
	 * JPQL Query - findParentByBbId1
	 *
	 */

	@SuppressWarnings("unchecked")
	@Transactional
	public Set<Parent> findParentByBbId1(String bbId1, int startResult, int maxRows) throws DataAccessException {
		Query query = createNamedQuery("findParentByBbId1", startResult, maxRows, bbId1);
		return new LinkedHashSet<Parent>(query.getResultList());
	}

	/**
	 * JPQL Query - findParentByBbId4Containing
	 *
	 */
	@Transactional
	public Set<Parent> findParentByBbId4Containing(String bbId4) throws DataAccessException {

		return findParentByBbId4Containing(bbId4, -1, -1);
	}

	/**
	 * JPQL Query - findParentByBbId4Containing
	 *
	 */

	@SuppressWarnings("unchecked")
	@Transactional
	public Set<Parent> findParentByBbId4Containing(String bbId4, int startResult, int maxRows) throws DataAccessException {
		Query query = createNamedQuery("findParentByBbId4Containing", startResult, maxRows, bbId4);
		return new LinkedHashSet<Parent>(query.getResultList());
	}

	/**
	 * JPQL Query - findParentByBbId1Containing
	 *
	 */
	@Transactional
	public Set<Parent> findParentByBbId1Containing(String bbId1) throws DataAccessException {

		return findParentByBbId1Containing(bbId1, -1, -1);
	}

	/**
	 * JPQL Query - findParentByBbId1Containing
	 *
	 */

	@SuppressWarnings("unchecked")
	@Transactional
	public Set<Parent> findParentByBbId1Containing(String bbId1, int startResult, int maxRows) throws DataAccessException {
		Query query = createNamedQuery("findParentByBbId1Containing", startResult, maxRows, bbId1);
		return new LinkedHashSet<Parent>(query.getResultList());
	}

	/**
	 * JPQL Query - findParentByName
	 *
	 */
	@Transactional
	public Set<Parent> findParentByName(String name) throws DataAccessException {

		return findParentByName(name, -1, -1);
	}

	/**
	 * JPQL Query - findParentByName
	 *
	 */

	@SuppressWarnings("unchecked")
	@Transactional
	public Set<Parent> findParentByName(String name, int startResult, int maxRows) throws DataAccessException {
		Query query = createNamedQuery("findParentByName", startResult, maxRows, name);
		return new LinkedHashSet<Parent>(query.getResultList());
	}

	/**
	 * JPQL Query - findParentByPhone
	 *
	 */
	@Transactional
	public Parent findParentByPhone(String phone) throws DataAccessException {

		return findParentByPhone(phone, -1, -1);
	}

	/**
	 * JPQL Query - findParentByPhone
	 *
	 */

	@Transactional
	public Parent findParentByPhone(String phone, int startResult, int maxRows) throws DataAccessException {
		try {
			Query query = createNamedQuery("findParentByPhone", startResult, maxRows, phone);
			return (com.baobao.domain.Parent) query.getSingleResult();
		} catch (NoResultException nre) {
			return null;
		}
	}

	/**
	 * JPQL Query - findParentByBbId3
	 *
	 */
	@Transactional
	public Set<Parent> findParentByBbId3(String bbId3) throws DataAccessException {

		return findParentByBbId3(bbId3, -1, -1);
	}

	/**
	 * JPQL Query - findParentByBbId3
	 *
	 */

	@SuppressWarnings("unchecked")
	@Transactional
	public Set<Parent> findParentByBbId3(String bbId3, int startResult, int maxRows) throws DataAccessException {
		Query query = createNamedQuery("findParentByBbId3", startResult, maxRows, bbId3);
		return new LinkedHashSet<Parent>(query.getResultList());
	}

	/**
	 * JPQL Query - findParentByPrimaryKey
	 *
	 */
	@Transactional
	public Parent findParentByPrimaryKey(String phone) throws DataAccessException {

		return findParentByPrimaryKey(phone, -1, -1);
	}

	/**
	 * JPQL Query - findParentByPrimaryKey
	 *
	 */

	@Transactional
	public Parent findParentByPrimaryKey(String phone, int startResult, int maxRows) throws DataAccessException {
		try {
			Query query = createNamedQuery("findParentByPrimaryKey", startResult, maxRows, phone);
			return (com.baobao.domain.Parent) query.getSingleResult();
		} catch (NoResultException nre) {
			return null;
		}
	}

	/**
	 * JPQL Query - findParentByAccountContaining
	 *
	 */
	@Transactional
	public Set<Parent> findParentByAccountContaining(String account) throws DataAccessException {

		return findParentByAccountContaining(account, -1, -1);
	}

	/**
	 * JPQL Query - findParentByAccountContaining
	 *
	 */

	@SuppressWarnings("unchecked")
	@Transactional
	public Set<Parent> findParentByAccountContaining(String account, int startResult, int maxRows) throws DataAccessException {
		Query query = createNamedQuery("findParentByAccountContaining", startResult, maxRows, account);
		return new LinkedHashSet<Parent>(query.getResultList());
	}

	/**
	 * JPQL Query - findParentByBbId3Containing
	 *
	 */
	@Transactional
	public Set<Parent> findParentByBbId3Containing(String bbId3) throws DataAccessException {

		return findParentByBbId3Containing(bbId3, -1, -1);
	}

	/**
	 * JPQL Query - findParentByBbId3Containing
	 *
	 */

	@SuppressWarnings("unchecked")
	@Transactional
	public Set<Parent> findParentByBbId3Containing(String bbId3, int startResult, int maxRows) throws DataAccessException {
		Query query = createNamedQuery("findParentByBbId3Containing", startResult, maxRows, bbId3);
		return new LinkedHashSet<Parent>(query.getResultList());
	}

	/**
	 * JPQL Query - findParentByBbId2Containing
	 *
	 */
	@Transactional
	public Set<Parent> findParentByBbId2Containing(String bbId2) throws DataAccessException {

		return findParentByBbId2Containing(bbId2, -1, -1);
	}

	/**
	 * JPQL Query - findParentByBbId2Containing
	 *
	 */

	@SuppressWarnings("unchecked")
	@Transactional
	public Set<Parent> findParentByBbId2Containing(String bbId2, int startResult, int maxRows) throws DataAccessException {
		Query query = createNamedQuery("findParentByBbId2Containing", startResult, maxRows, bbId2);
		return new LinkedHashSet<Parent>(query.getResultList());
	}

	/**
	 * JPQL Query - findParentByRelation
	 *
	 */
	@Transactional
	public Set<Parent> findParentByRelation(Integer relation) throws DataAccessException {

		return findParentByRelation(relation, -1, -1);
	}

	/**
	 * JPQL Query - findParentByRelation
	 *
	 */

	@SuppressWarnings("unchecked")
	@Transactional
	public Set<Parent> findParentByRelation(Integer relation, int startResult, int maxRows) throws DataAccessException {
		Query query = createNamedQuery("findParentByRelation", startResult, maxRows, relation);
		return new LinkedHashSet<Parent>(query.getResultList());
	}

	/**
	 * JPQL Query - findParentByBbId5
	 *
	 */
	@Transactional
	public Set<Parent> findParentByBbId5(String bbId5) throws DataAccessException {

		return findParentByBbId5(bbId5, -1, -1);
	}

	/**
	 * JPQL Query - findParentByBbId5
	 *
	 */

	@SuppressWarnings("unchecked")
	@Transactional
	public Set<Parent> findParentByBbId5(String bbId5, int startResult, int maxRows) throws DataAccessException {
		Query query = createNamedQuery("findParentByBbId5", startResult, maxRows, bbId5);
		return new LinkedHashSet<Parent>(query.getResultList());
	}

	/**
	 * JPQL Query - findParentByNameContaining
	 *
	 */
	@Transactional
	public Set<Parent> findParentByNameContaining(String name) throws DataAccessException {

		return findParentByNameContaining(name, -1, -1);
	}

	/**
	 * JPQL Query - findParentByNameContaining
	 *
	 */

	@SuppressWarnings("unchecked")
	@Transactional
	public Set<Parent> findParentByNameContaining(String name, int startResult, int maxRows) throws DataAccessException {
		Query query = createNamedQuery("findParentByNameContaining", startResult, maxRows, name);
		return new LinkedHashSet<Parent>(query.getResultList());
	}

	/**
	 * JPQL Query - findParentByAccount
	 *
	 */
	@Transactional
	public Set<Parent> findParentByAccount(String account) throws DataAccessException {

		return findParentByAccount(account, -1, -1);
	}

	/**
	 * JPQL Query - findParentByAccount
	 *
	 */

	@SuppressWarnings("unchecked")
	@Transactional
	public Set<Parent> findParentByAccount(String account, int startResult, int maxRows) throws DataAccessException {
		Query query = createNamedQuery("findParentByAccount", startResult, maxRows, account);
		return new LinkedHashSet<Parent>(query.getResultList());
	}

	/**
	 * JPQL Query - findAllParents
	 *
	 */
	@Transactional
	public Set<Parent> findAllParents() throws DataAccessException {

		return findAllParents(-1, -1);
	}

	/**
	 * JPQL Query - findAllParents
	 *
	 */

	@SuppressWarnings("unchecked")
	@Transactional
	public Set<Parent> findAllParents(int startResult, int maxRows) throws DataAccessException {
		Query query = createNamedQuery("findAllParents", startResult, maxRows);
		return new LinkedHashSet<Parent>(query.getResultList());
	}

	/**
	 * Used to determine whether or not to merge the entity or persist the entity when calling Store
	 * @see store
	 * 
	 *
	 */
	public boolean canBeMerged(Parent entity) {
		return true;
	}
}
